﻿@model CategoryCreator

@section styles{
    @Styles.Render("~/Content/treeview.css")
}

@{
    string title = ViewBag.Title;
    string returnListUrl = ViewBag.ReturnListUrl;
    List<SelectListItem> propertyTypeDDL = ViewBag.PropertyTypeDDL;

    string controller = "category";

    ViewBag.Title = "Tạo mới " + title;
}

<section class="content-header">
    <h1>
        @title.ToUpper() <small>tạo mới</small>
    </h1>
    <ol class="breadcrumb">
        <li>
            <a href="@Url.Action("Index", "Admin")">
                <i class="fa fa-home"></i> Trang chủ
            </a>
        </li>
        <li>
            <a href="@Url.Action("Index")">Danh sách @title</a>
        </li>
        <li class="active">Tạo mới</li>
    </ol>
</section>

<section class="content">
    @using (Html.BeginForm("Create", "Category", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @Html.Hidden("ReturnListUrl", returnListUrl)

        <div class="box box-primary">
            <div class="box-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="control-label">Thuộc nhóm</label>
                            <div style="height: 450px; overflow-y: scroll;">
                                <ul class="tree">
                                    <li><span class="active" data-value="">KHÔNG THUỘC NHÓM NÀO!</span></li>
                                    @Html.Raw(ViewBag.CategoryTreeView)
                                </ul>
                            </div>
                            @Html.HiddenFor(m => m.ParentId)
                            @Html.ValidationMessageFor(m => m.ParentId)
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="control-label">Tên danh mục</label>
                            @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
                            @Html.ValidationMessageFor(m => m.Name)
                        </div>
                        <div class="form-group">
                            <label class="control-label">Tên hiển thị menu</label>
                            @Html.TextBoxFor(m => m.DisplayName, new { @class = "form-control" })
                            @Html.ValidationMessageFor(m => m.DisplayName)
                        </div><div class="form-group">
                            <label class="control-label">Ảnh đại diện</label>
                            <input name="Image" type="file" class="form-control" accept="image/*">
                            @Html.ValidationMessageFor(m => m.Image)
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label class="control-label">Các thuộc tính</label>
                            <div class="well">
                                <div class="row">
                                    @foreach (var propType in propertyTypeDDL)
                                    {
                                        <div class="col-md-6">
                                            @Html.CheckBox("cb" + propType.Text) @propType.Text
                                        </div>
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-footer text-right">
                <a href="@Request.UrlReferrer" class="btn btn-default pull-left">
                    <i class="fa fa-chevron-left"></i> Quay lại
                </a>
                <button type="reset" class="btn btn-warning">
                    <i class="fa fa-repeat"></i> Mặc định
                </button>
                <button type="submit" class="btn btn-success">
                    <i class="fa fa-check"></i> Xác nhận
                </button>
            </div>
        </div>
    }
</section>

@section scripts{
    <script>
        $('.expander').nextAll('ul').attr('class', 'expanded');

        $('.expander').addClass('expanded');

        $('.expander').click(function () {
            $(this).toggleClass('expanded')
              .nextAll('ul:first').toggleClass('expanded');
            return true;
        });

        $('.tree span').click(function () {
            var parentId = $(this).attr('data-value');
            $('#ParentId').attr('value', parentId);

            $('.tree span').removeClass('active');
            $(this).addClass('active')
        });

        ActiveMenu('@controller');
    </script>
}